package gr.unipi.mscd1;

public class StInfo extends SnmpGenInfo {
	private int id;
	private String descr;
	private int type;
	private int allocUnit;
	private int size;
	
	public StInfo(int id, String descr, int type, int allocUnit, int size) {
		super();
		this.id = id;
		this.descr = descr;
		this.type = type;
		this.allocUnit = allocUnit;
		this.size = size;
	}
	
	public StInfo() {
		super();
		this.id = 0;
		this.descr = "";
		this.type = 0;
		this.allocUnit = 0;
		this.size = 0;
	}
	
	public StInfo(StorageInfo info) {
		super();
		this.id = (Integer)info.getOids().get(0).getValue();
		this.descr = (String)info.getOids().get(1).getValue();
		String typeTmp = (String)info.getOids().get(2).getValue();
		int from = typeTmp.lastIndexOf(".");
		this.type = Integer.parseInt(typeTmp.substring(from + 1));
		this.allocUnit = (Integer)info.getOids().get(3).getValue();
		this.size = (Integer)info.getOids().get(4).getValue();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDescr() {
		return descr;
	}

	public void setDescr(String descr) {
		this.descr = descr;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	public String getTypeDescr() {
		if (!storeTypeDescr.containsKey(type)) {
			return type + "(" + type + ")";
		}
		return storeTypeDescr.get(type) + "(" + type + ")";
	}

	public int getAllocUnit() {
		return allocUnit;
	}

	public void setAllocUnit(int allocUnit) {
		this.allocUnit = allocUnit;
	}

	public int getSize() {
		return size;
	}

	public void setSize(int size) {
		this.size = size;
	}
	
	public double getSizeInKBs() {
		final double KB = 1024.0;
		double size = getSize();
		double alloc = getAllocUnit();
		
		if (alloc != 0) {
			return KB * size / alloc;
		}
		return 0;
	}
	
}
